--[[
	等候界面
		2016_04_27 C.P
	功能：阻断用户输入，防止不必要的情况
]]
local ExternalFun = appdf.req(appdf.EXTERNAL_SRC .. "ExternalFun")
local LoadingLayer = class("LoadingLayer", function(gameid)
	if gameid then
		return display.newLayer(cc.c4b(0, 0, 0, 255))
	else
		return display.newLayer(cc.c4b(0, 0, 0, 180))
	end
end)
function LoadingLayer:makeAzhezhao()
	self.bar:setVisible(false)
	self:setOpacity(0)
end
function LoadingLayer:ctor(gameid,showSplash)
	
	if width == nil or height == nil then
		self:setContentSize(display.width,display.height)
	else
		self:setContentSize(width,height)
	end
	
	local function onTouch(eventType, x, y)
        return true
    end
	self:setTouchEnabled(true)
	self:registerScriptTouchHandler(onTouch)
    local rootLayer, csbNode = ExternalFun.loadRootCSB( "Logon/loadLayer.csb", self )
	local gameImgbg = csbNode:getChildByName("gameImgbg")
	local bar = csbNode:getChildByName("loadbar")
	self.bar = bar
	if not gameid  then
		gameImgbg:loadTexture("public/blank.png")
		bar:setPositionY(375 )

	else
		local gametype = GlobalUserItem.tb_gameType[tostring(gameid)] or 1
	
		local sp_patch = string.format("Logon/load_%d_%d.jpg",gameid,gametype) 
		if gametype <= 1 or not cc.FileUtils:getInstance():isFileExist(sp_patch) then
			 sp_patch = "Logon/load_"..gameid..".jpg"
		end
		
		if showSplash and cc.FileUtils:getInstance():isFileExist("public/pad_loading.png") then
			sp_patch = "public/pad_loading.png"
			local ba_sp = display.newSprite(sp_patch)
			ba_sp:setPosition(cc.p(display.width/2,display.height))
			ba_sp:setAnchorPoint(cc.p(0.5,1))
			local size = ba_sp:getContentSize()
			ba_sp:setScale(display.width/size.width)
			-- ba_sp:setLocalZOrder(0)
			rootLayer:addChild(ba_sp,-1)
			gameImgbg:setVisible(false)
		elseif  cc.FileUtils:getInstance():isFileExist("bg_splash.png") then
			sp_patch = "bg_splash.png"
			local ba_sp = display.newSprite(sp_patch)
			ba_sp:setPosition(cc.p(display.width/2,display.height))
			ba_sp:setAnchorPoint(cc.p(0.5,1))
			local size = ba_sp:getContentSize()
			ba_sp:setScale(display.width/size.width)
			-- ba_sp:setLocalZOrder(0)
			rootLayer:addChild(ba_sp,-1)
			gameImgbg:setVisible(false)
		else
			gameImgbg:loadTexture(sp_patch)
		end
		gameImgbg:setScale(1.05)
		bar:setPositionY(154 )
		ExternalFun.FixCenterPosY(gameImgbg)

	end

end

return LoadingLayer